package com.tg.network.http;

import androidx.core.util.Consumer;

import com.tange.base.toolkit.DateUtil;
import com.tange.core.data.structure.Ret;
import com.tange.core.device.manage.DeviceTime;
import com.tg.appcommon.android.TGLog;
import com.tange.core.backend.service.http.ClientObserver;
import com.tg.network.socket.http.TGHttp;

import java.util.HashMap;
import java.util.TimeZone;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Describe:
 * Created by Rance Rang on 2019/5/15.
 * <p>
 * Copyright (c) Tange.Inc All rights reserved.
 */
public class TimeZoneUtils {

    public static void setTimezone(String deviceID) {
        TimeZone timeZone = TimeZone.getDefault();
        String zone = timeZone.getID();
        String time = DateUtil.getTimeZone();
        setTimezone(deviceID, time, zone);
    }
    public static void setUserTimezone(){
        TimeZone timeZone = TimeZone.getDefault();
        String zone = timeZone.getID();
        String time = DateUtil.getTimeZone();
        setUserTimezone(time, zone);
    }


    public static void setTimezone(String deviceID, String time, String zone) {
        DeviceTime.INSTANCE.modifyTimeZone(deviceID, time, zone, ret -> TGLog.d("modifyTimeZone ret: " + ret));
    }

    public static void setUserTimezone(String time, String zone) {
        HashMap<String, String> map = new HashMap<>();
        map.put("time", time);
        map.put("zone", zone);
        TGLog.d("time :" + time + " zone: " + zone);
        TGHttp.getInstance().setUserTimeZone(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ClientObserver<String>() {
                    @Override
                    protected void onSuccess(String content) {
                    }
                });
    }
}
